/*
* Copyright (C) Microsoft. All rights reserved.  
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not 
* use this file except in compliance with the License.  You may obtain a copy 
* of the License at http://www.apache.org/licenses/LICENSE-2.0  
* 
* THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 
* WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 
* MERCHANTABLITY OR NON-INFRINGEMENT. 
*
* See the Apache License, Version 2.0 for specific language governing 
* permissions and limitations under the License.
*
*/
#pragma once

#include <baja/observable.hpp>
#include <baja/model/generic_model_interface.h>

namespace baja { namespace model {

namespace b = baja;

class generic_model : public igeneric_model
{
public:
    generic_model();

    // igeneric_model
    b::int32 addGenericObserver(const std::shared_ptr<igeneric_model_observer>& observer);
    void removeGenericObserver(const std::shared_ptr<igeneric_model_observer>& observer);
    void removeGenericObserver(const b::int32& cookie);

    void setGenericTypeToken(const b::uint32& genericTypeToken);
    b::uint32 genericTypeToken();

    void setGenericIdentity(const b::uint32& genericIdentity);
    b::uint32 genericIdentity();

    void setGenericParent(const std::shared_ptr<igeneric_model>& parent);
    std::shared_ptr<igeneric_model> genericParent();

protected:
    void fireChangedEvent();

private:
    b::uint32 _genericTypeToken;
    b::uint32 _genericIdentity;
    std::weak_ptr<igeneric_model> _genericParent;

    // observers
    b::observable_source<igeneric_model_observer> _eventSource;
};


}} // baja::model